/**
 * 
 */
package co.gov.medellin.sdep.sisdep.operativa.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.operativa.exception.ComparendoNegReinException;
import co.gov.medellin.sdep.sisdep.operativa.exception.ComparendoNegReinRuntimeException;
import co.gov.medellin.sdep.sisdep.operativa.exception.descriptor.ComparendoNegReinMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ComparendoNegRein;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IComparendoNegReinDAOT;

/**
 * @author Usuario
 *
 */
public class ComparendoNegReinServiceImpl extends BaseService implements IComparendoNegReinService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IComparendoNegReinDAOT comparendoNegReinDAO;

	/**
	 * 
	 */
	public ComparendoNegReinServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(ComparendoNegRein comparendoNegRein) throws ComparendoNegReinException {
		try{
			comparendoNegRein.setUsuarioCrea(getPrincipalUser());
			comparendoNegRein.setFechaCrea(new Date());
			getComparendoNegReinDAO().insert(comparendoNegRein);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoNegRein.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ComparendoNegReinException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ComparendoNegReinException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(ComparendoNegRein comparendoNegRein) throws ComparendoNegReinException {
		try{
			comparendoNegRein.setUsuarioModifica(getPrincipalUser());
			comparendoNegRein.setFechaModifica(new Date());
			getComparendoNegReinDAO().update(comparendoNegRein);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoNegRein.getCodigo()
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(ComparendoNegRein comparendoNegRein) throws ComparendoNegReinException {
		try {
			comparendoNegRein.setUsuarioModifica(getPrincipalUser());
			comparendoNegRein.setFechaModifica(new Date());
			getComparendoNegReinDAO().delete(comparendoNegRein);
		}catch (Exception e) {
			Object [] infoError = {
				comparendoNegRein.getCodigo()
			};
			throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, ComparendoNegRein comparendoNegRein) throws ComparendoNegReinException {
		try{
			//return getComparendoNegReinDAO().getAllComparendoNegReinPaginated(start, max, criteria);
			return getComparendoNegReinDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByRadicado(int start,int max, ComparendoNegRein comparendoNegRein) throws ComparendoNegReinException {
		try{
			//return getComparendoNegReinDAO().getAllComparendoNegReinPaginated(start, max, criteria);
			return getComparendoNegReinDAO().loadByRadicado(comparendoNegRein);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}	

	/**
	 * 
	 */
	public final ComparendoNegRein get(long id) throws ComparendoNegReinException {
		try{
			return getComparendoNegReinDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ComparendoNegReinRuntimeException(new ComparendoNegReinMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IComparendoNegReinDAOT getComparendoNegReinDAO() {
		return comparendoNegReinDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setComparendoNegReinDAO(IComparendoNegReinDAOT comparendoNegReinDAO) {
		this.comparendoNegReinDAO = comparendoNegReinDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
